package com.itheima.filter;

import com.alibaba.fastjson.JSON;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//用户登录检验(拦截器版)
@Component
public class LoginCheckInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        if (request.getSession().getAttribute("employee") != null) {
            return true;
        }
        if (request.getSession().getAttribute("user") != null) {
            return true;
        }
        response.getWriter().write(JSON.toJSONString("NOTLOGIN"));
        return false;
    }
}
